package com.application.bisabahasakorea;

import android.os.Bundle;
import android.app.Activity;
//import android.app.LauncherActivity;
import android.content.Context;
import android.content.Intent;
//import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
//import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class BisaBahasaKoreaActivity extends Activity implements OnItemClickListener {
	 
    static final LauncherIcon[] ICONS = {
    		new LauncherIcon(R.drawable.ic_southkorea, "Pengenalan Dasar", "ic_southkorea.png"),
    		new LauncherIcon(R.drawable.ic_abc, "Huruf", "ic_abc.png"),
            new LauncherIcon(R.drawable.ic_number, "Angka", "ic_number.png"),
            new LauncherIcon(R.drawable.ic_conversation, "Percakapan", "ic_conversation.png"),
            new LauncherIcon(R.drawable.ic_favorite, "Favorite", "ic_favorite.png"),
       };
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dashboard);
        
        GridView gridview = (GridView) findViewById(R.id.dashboard_grid);
        gridview.setAdapter(new ImageAdapter(this));
        gridview.setOnItemClickListener(this);
 
        // Hack to disable GridView scrolling
        gridview.setOnTouchListener(new OnTouchListener() {
           // @Override
            public boolean onTouch(View v, MotionEvent event) {
                return event.getAction() == MotionEvent.ACTION_MOVE;
            }
        });
    }
 
   // @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        switch(position){
        case 0:
			Intent intent = new Intent(this, PengenalanDasarActivity.class);
		    startActivity(intent);
		    break;
		    
		case 1:
    		Intent intent1 = new Intent(this, MenuHurufActivity.class);
            startActivity(intent1);
            break;
            
        case 2:
    		Intent intent2 = new Intent(this, MenuAngkaActivity.class);
            startActivity(intent2);
            break;
            
        case 3:
    		Intent intent3 = new Intent(this, MenuPercakapanActivity.class);
            startActivity(intent3);
            break;
        
		case 4:
			Intent intent4 = new Intent(this, FavoriteActivity.class);
		    startActivity(intent4);
		    break;
		    
		}
    }
 
    static class LauncherIcon {
        final String text;
        final int imgId;
        final String map;
 
        public LauncherIcon(int imgId, String text, String map) {
            super();
            this.imgId = imgId;
            this.text = text;
            this.map = map;
        }
 
    }
 
    static class ImageAdapter extends BaseAdapter {
        private Context mContext;
 
        public ImageAdapter(Context c) {
            mContext = c;
        }
 
     //   @Override
        public int getCount() {
            return ICONS.length;
        }
 
       // @Override
        public LauncherIcon getItem(int position) {
            return null;
        }
 
        //@Override
        public long getItemId(int position) {
            return 0;
        }
 
        static class ViewHolder {
            public ImageView icon;
            public TextView text;
        }
 
        // Create a new ImageView for each item referenced by the Adapter
       // @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            ViewHolder holder;
            
            if (v == null) {
                LayoutInflater vi = (LayoutInflater) mContext.getSystemService(
                    Context.LAYOUT_INFLATER_SERVICE);
 
                v = vi.inflate(R.layout.dashboard_icon, null);
                holder = new ViewHolder();
                holder.text = (TextView) v.findViewById(R.id.dashboard_icon_text);
                holder.icon = (ImageView) v.findViewById(R.id.dashboard_icon_img);
                v.setTag(holder);
            } else {
                holder = (ViewHolder) v.getTag();
            }
 
            holder.icon.setImageResource(ICONS[position].imgId);
            holder.text.setText(ICONS[position].text);
 
            return v;
        }
    }
}
